home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 676-700 / 687 / xprd / src / intuition.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  5KB  |  197 lines

  1.  
  2. /*
  3.     Intuition.c
  4.     -----------
  5.     Intuition functions for XPR
  6.  
  7. */
  8.  
  9. #include <proto/intuition.h>
  10. #include <proto/exec.h>
  11. #include <proto/graphics.h>
  12. #include <string.h>
  13. #include "xproto.h"
  14. #include <intuition/intuitionbase.h>
  15.  
  16. static int fontoffset;
  17.  
  18. extern void getcdname(char*);
  19. extern short os13;
  20. extern short nowindow;
  21.  
  22. void plog(char,char*,...);
  23. void printf(char*,...);
  24.  
  25. extern short checkcarrier,windowx,windowy;
  26. extern long chk4cd(void);
  27.  
  28. extern void sprintf(char*,char*,);
  29.  
  30. extern struct Screen *firstscreen;
  31. extern struct IntuitionBase *IntuitionBase;
  32.  
  33. long xpr_windowsig;
  34. static struct Window *w;
  35. static struct RastPort *rp;
  36. static struct NewWindow nw={0,0,520,136,
  37.     2,1,
  38.     CLOSEWINDOW,
  39.     WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|RMBTRAP,
  40.     0,0,0,0,0,0,0,0,0,
  41.     WBENCHSCREEN};
  42.  
  43. static void print(int x,int y,char *s)
  44. {
  45.     char buff[52];
  46.     Move(rp,8+(x<<3),15+(y<<3)+fontoffset);
  47.     sprintf(buff,"%-50.50s",s);
  48.     Text(rp,buff,50);
  49. }
  50. static void xprint(int x,int y,char *s)
  51. {
  52.     Move(rp,8+(x<<3),15+(y<<3)+fontoffset);
  53.     Text(rp,s,strlen(s));
  54. }
  55. static void nprint(int x,int y,int v)
  56. {
  57.     char buff[8];
  58.     if(v==-1) return;
  59.     sprintf(buff,"%-7ld",v);
  60.     Move(rp,8+(x<<3),15+(y<<3)+fontoffset);
  61.     Text(rp,buff,7);
  62. }
  63.  
  64. /* Opens the window */
  65. static struct TextAttr top80={"topaz.font",8,0,0};
  66. int xpr_opendisplay(void)
  67. {
  68.     if(nowindow) return(0);
  69.     if((firstscreen==(struct Screen*)-1)) firstscreen=IntuitionBase->FirstScreen;
  70.     if(firstscreen) {
  71.     nw.Type=firstscreen->Flags&SCREENTYPE;
  72.     nw.Screen=firstscreen;
  73.     }
  74.     if(windowy<0) windowy=0;
  75.     if(windowx<0) windowx=0;
  76.     if(!os13) {
  77.     struct Screen *fscr=firstscreen;
  78.  
  79.     if(!fscr) fscr=LockPubScreen(0);
  80.     if(fscr) {
  81.         fontoffset=fscr->BarHeight-10;
  82.         if(!firstscreen) UnlockPubScreen(0,fscr);
  83.     }
  84.     }    
  85.  
  86.     nw.Height+=fontoffset;
  87.  
  88.     if(firstscreen) {
  89.         if(windowy+nw.Height>firstscreen->Height) windowy=firstscreen->Height-nw.Height-1;
  90.         if(windowx+520>firstscreen->Width) windowx=firstscreen->Width-521;
  91.     }
  92.     nw.TopEdge=windowy;
  93.     nw.LeftEdge=windowx;
  94.     if(!(w=OpenWindow(&nw))) return(-1);
  95.     xpr_windowsig=1<<(w->UserPort->mp_SigBit);
  96.     SetFont(rp=w->RPort,OpenFont(&top80));
  97.     SetWindowTitles(w,"XPR Transmission Status Window",
  98.     "eXternal PRotocol Driver V1.13, Written & © 1991 by Oliver Wagner");
  99.     SetDrMd(rp,JAM2);
  100.     SetAPen(rp,2);
  101.     Move(rp,8,92+fontoffset);
  102.     Draw(rp,510,92+fontoffset);
  103.     SetAPen(rp,3);
  104.     xprint(2,1,"Protocol:");
  105.     xprint(2,2,"Filename:");
  106.     xprint(2,3,"Filesize:");
  107.     xprint(3,4,"Message:");
  108.     xprint(1,5,"Last Err.:");
  109.     xprint(4,6,"Blocks:");
  110.     xprint(28,6,"Blocksize:");
  111.     xprint(5,7,"Bytes:");
  112.     xprint(31,7,"Errors:");
  113.     xprint(3,8,"Elapsed:");
  114.     xprint(29,8,"Expected:");
  115.     xprint(2,9,"Datarate:");
  116.     xprint(29,9,"Blockchk:");
  117.  
  118.     xprint(4,11,"Device:");
  119.     xprint(1,12,"BPS/Flags:");
  120.     xprint(8,13,"CD:");
  121.     xprint(6,14,"Path:");    
  122.  
  123.     SetAPen(rp,1);
  124.     return(0);
  125. }
  126.  
  127. extern char *devname;
  128. extern char *tempdir;
  129. extern short devnum,checkcarrier;
  130. extern short sharedaccess,rtscts;
  131. extern int speed;
  132.  
  133. void initdisplay(void)
  134. {
  135.         char buff[256];
  136.     if(nowindow) return;
  137.     sprintf(buff,"%-.30s (%ld)",devname,(long)devnum);
  138.     xprint(12,11,buff);
  139.     sprintf(buff,"%ld %s%s",speed,(sharedaccess)?"(SHARED) ":"",(rtscts)?"(RTS/CTS)":"");
  140.     xprint(12,12,buff);
  141.         xprint(12,13,(checkcarrier)?"enabled":"disabled");
  142.     getcdname(buff);
  143.         xprint(12,14,buff);
  144. }
  145.  
  146. /* Closes the Window ;-) */
  147. void xpr_closedisplay(void)
  148. {
  149.     if(w) CloseWindow(w);
  150. }
  151.  
  152. /* Makes Displayupdate */
  153. void __saveds xpr_displayupdate(struct XPR_UPDATE *xu)
  154. {
  155.     long ud=xu->xpru_updatemask;
  156.  
  157.     if(nowindow) return;
  158.     if(ud&XPRU_PROTOCOL) print(12,1,xu->xpru_protocol);
  159.     if(ud&XPRU_FILENAME) print(12,2,xu->xpru_filename);
  160.     if(ud&XPRU_FILESIZE) nprint(12,3,xu->xpru_filesize);
  161.     if(ud&XPRU_MSG) {
  162.     plog('+',"MSG: %s\n",xu->xpru_msg);
  163.     print(12,4,xu->xpru_msg);
  164.     }
  165.     if(ud&XPRU_ERRORMSG) {
  166.     plog('+',"ERROR: %s\n",xu->xpru_errormsg);
  167.     print(12,5,xu->xpru_errormsg);
  168.     }
  169.     if(ud&XPRU_BLOCKS) nprint(12,6,xu->xpru_blocks);
  170.     if(ud&XPRU_BLOCKSIZE) nprint(39,6,xu->xpru_blocksize);
  171.     if(ud&XPRU_BYTES) nprint(12,7,xu->xpru_bytes);
  172.     if(ud&XPRU_ERRORS) nprint(39,7,xu->xpru_errors);
  173.     if(ud&XPRU_ELAPSEDTIME) xprint(12,8,xu->xpru_elapsedtime);
  174.     if(ud&XPRU_EXPECTTIME) xprint(39,8,xu->xpru_expecttime);
  175.     if(ud&XPRU_DATARATE) nprint(12,9,xu->xpru_datarate);
  176.     if(ud&XPRU_BLOCKCHECK) xprint(39,9,xu->xpru_blockcheck);
  177. }
  178.  
  179. /* Checks for User Abort */
  180. long __saveds xpr_chk4abort(void)
  181. {
  182.     struct IntuiMessage *im=0;
  183.     long ret=0;
  184.  
  185.     if(!nowindow) im=GetMsg(w->UserPort);
  186.  
  187.     if(checkcarrier) {
  188.         if(!chk4cd()) {
  189.         ret=-1;
  190.         if(!nowindow) xprint(12,13," ");
  191.     }
  192.     }
  193.     if(!im) return(ret);  
  194.     ReplyMsg(im);
  195.     return(-1);
  196. }
  197.